<?php
require_once('business/Controller.php');

class SedController extends FRM_Controller
{
	private $cfer = array();
    
	// Constructor overloading
	function __construct()
	{
		$this->initialize();
        $this->checkPermission();
        
        FRM_XOAD::register('server', $this );
	}
	/**
	 * Initialize some system variable
	 */
	public function initialize()
	{
		Parameter::loadAllParameters();		
		
		$smarty = FRM::load('smarty');
		$menus = Controller::getList();
		
		$contr = Controller::getCurrent();
       
		$act = FRM_Request::getAction();
        if(empty($act))
            $act = 'index';
 
		$smarty->assign('act', $act);
		$smarty->assign('language', FRM_MultiLanguage::getLanguage());		
        $smarty->assign('contr', $contr);
        $smarty->assign('alias_string', $contr->alias);			
	    $smarty->assign('menus', $menus);		
	}
    
    /**
    * @desc Check user permission based on _permission array
    */
    public function checkPermission()
    {
    	
        $contr = FRM_Request::getController();
        $contr = substr($contr, strpos($contr, '_') + 1); 
        
        if ($contr == 'admin')
        {
        	$current_user = unserialize(FRM_Session::get('user_serialize_admin'));
        
            if ($current_user && $current_user->id)
            {
            	if ($current_user->is_controller == User::QUANTRI ){
            		return true;
                }
            	else if ($contr == 'home')
            		return true;
            	else 
            	{
            		$arr_controller = FRM_Session::get('arr_controller');
            		if (in_array($contr, $arr_controller))
            			return true;
                    
            		FRM::redirect(APPLICATION_URL . '/admin/index/');
	           	}
            }
            else
            {
            	FRM::redirect(APPLICATION_URL . '/login/login/');
            }
        }
        else 
        {
    		return true;
        }
    }
}